package cn.ly.net.rpc;

import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 简单的基于tcp协议的rpc远程调用的client
 * @author liuyu
 *
 */


public class PRCClient {

	public static void main(String[] args) throws Exception {
		//创建client的socket对象
		//Socket(String host, int port) 
		Socket s = new Socket("localhost",8888);
		
		//获得输出流
		OutputStream os = s.getOutputStream();
		HelloRpc helloRpc = new HelloRpc();
		Object[] o = {helloRpc,"ly"};
		ObjectOutputStream oos = new ObjectOutputStream(os);
		oos.writeObject(o);
		os.flush();
		
		Thread.sleep(1000*10);
		InputStream is = s.getInputStream();
		byte[] bys = new byte[1024];
		is.read(bys);
		System.out.println("client:" + new String(bys));
		s.close();
	}
}
